Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
decamelize
Advanced tools
Convert a camelized string into a lowercased one with a custom separator: unicornRainbow → unicorn_rainbow
The decamelize npm package is used to convert a string from camelCase to a lower case string with a custom separator (defaulting to an underscore). It is useful for transforming variable names or keys in objects from camelCase to a format that is more common in other languages or contexts, such as snake_case for database fields or kebab-case for CSS class names.
Decamelize a string
Converts 'myCamelCaseString' to 'my_camel_case_string' using the default separator.
"myCamelCaseString".decamelize()
Decamelize with a custom separator
Converts 'myCamelCaseString' to 'my-camel-case-string' using a custom separator ('-').
"myCamelCaseString".decamelize('-')
Preserve consecutive uppercase characters
Converts 'myURLString' to 'my_url_string', preserving the consecutive uppercase characters.
"myURLString".decamelize('_', { preserveConsecutiveUppercase: true })
The snake-case package converts strings to snake_case. It is similar to decamelize but is specifically tailored to produce snake_case without providing options for custom separators.
The kebab-case package is designed to convert strings to kebab-case. While it serves a similar purpose in changing the case of strings, it is focused on kebab-case rather than providing a customizable separator.
The change-case package is a more comprehensive string transformation library that includes a variety of case conversion functions, including decamelize. It offers a broader set of functionalities compared to the single-purpose decamelize package.
Convert a camelized string into a lowercased one with a custom separator
Example:unicornRainbow
→unicorn_rainbow
If you use this on untrusted user input, don't forget to limit the length to something reasonable.
npm install decamelize
import decamelize from 'decamelize';
decamelize('unicornRainbow');
//=> 'unicorn_rainbow'
decamelize('unicornRainbow', {separator: '-'});
//=> 'unicorn-rainbow'
decamelize('testGUILabel', {preserveConsecutiveUppercase: true});
//=> 'test_GUI_label'
decamelize('testGUILabel', {preserveConsecutiveUppercase: false});
//=> 'test_gui_label'
Type: string
Type: object
Type: string
Default: '_'
Character or string inserted to separate words in string
.
import decamelize from 'decamelize';
decamelize('unicornRainbow');
//=> 'unicorn_rainbow'
decamelize('unicornRainbow', {separator: '-'});
//=> 'unicorn-rainbow'
Type: boolean
Default: false
Preserve sequences of uppercase characters.
import decamelize from 'decamelize';
decamelize('testGUILabel');
//=> 'test_gui_label'
decamelize('testGUILabel', {preserveConsecutiveUppercase: true});
//=> 'test_GUI_label'
See camelcase
for the inverse.
FAQs
Convert a camelized string into a lowercased one with a custom separator: unicornRainbow → unicorn_rainbow
The npm package decamelize receives a total of 24,879,912 weekly downloads. As such, decamelize popularity was classified as popular.
We found that decamelize demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.